# -*- coding:utf-8 -*-

import smbus
import time


# 改：
# 向平台已经创建的数据流发送数据点
import urllib2
import json
import datetime
#



F8X16=										    \
(										    \
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,\
  0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
  0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,\
  0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,\
  0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,\
  0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,\
  0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,\
  0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,\
  0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,\
  0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,\
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,\
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,\
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,\
  0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,\
  0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,\
  0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,\
  0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,\
  0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,\
  0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,\
  0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,\
  0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,\
  0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,\
  0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,\
  0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,\
  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,\
  0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,\
  0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,\
  0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,\
  0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,\
  0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,\
  0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,\
  0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,\
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,\
  0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,\
  0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,\
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,\
  0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,\
  0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,\
  0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,\
  0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,\
  0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,\
  0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,\
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,\
  0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,\
  0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,\
  0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,\
  0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,\
  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,\
  0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,\
  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,\
  0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,\
  0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,\
  0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,\
  0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,\
  0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,\
  0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,\
  0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,\
  0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,\
  0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,\
  0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,\
  0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,\
  0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,\
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,\
  0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,\
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,\
  0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,\
  0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,\
  0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,\
  0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,\
  0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,\
  0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,\
  0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,\
  0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,\
  0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,\
  0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,\
  0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,\
  0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,\
  0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,\
  0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,\
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,\
  0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,\
  0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,\
  0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,\
  0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,\
  0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,\
  0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,\
  0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,\
  0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
)

F_SIGN = (								      \
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, \
0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00,\
0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00\
)

Hzk = 					\
[					\
[0x06,0x09,0x09,0xE6,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x02,0x04,0x1E,0x00,0x00],\
[0x00,0x00,0x00,0x07,0x1F,0x30,0x20,0x40,0x40,0x40,0x40,0x40,0x20,0x10,0x00,0x00],\
[0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00],\
[0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00],\
[0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00],\
[0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00],\
[0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00],\
[0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00],\
[0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00],\
[0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00],\
[0x00,0x00,0x7C,0x82,0x82,0x7C,0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x00,0x00],\
[0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x3E,0x41,0x41,0x3E,0x00,0x00,0x00,0x00],\
]

eSHT2xOled_Addressess = 0x40

eTempHoldCmd= 0xE3

eRHumidityHoldCmd= 0xE5

eTempNoHoldCmd= 0xF3

eRHumidityNoHoldCmd= 0xF5

writeUserRegister= 0xE6

readUserRegister= 0xE7

softReset= 0xFE

i2c = smbus.SMBus(1)



Oled_Address = 0x3C







def Clear_Oled():
	for i in range(8):
		i2c.write_byte_data(Oled_Address , 0x00, 0xB0 + i)
        	i2c.write_byte_data(Oled_Address , 0x00, 0x02)
        	i2c.write_byte_data(Oled_Address , 0x00, 0x10)
		for k in range(128):
            		i2c.write_byte_data(Oled_Address , 0x40, 0x00)
def On_Oled():
	for i in range(8):
		i2c.write_byte_data(Oled_Address , 0x00, 0xB0 + i)
        	i2c.write_byte_data(Oled_Address , 0x00, 0x02)
        	i2c.write_byte_data(Oled_Address , 0x00, 0x10)
		for k in range(128):
            		i2c.write_byte_data(Oled_Address , 0x40, 0xFF)

def OLED_Set_Pos(x, y):
	i2c.write_byte_data(Oled_Address, 0x00, 0xb0 + y)
	i2c.write_byte_data(Oled_Address, 0x00, ((x & 0xf0) >> 4) | 0x10)
	i2c.write_byte_data(Oled_Address, 0x00, (x & 0x0f) | 0x01)

def OLED_ShowChar(x, y, chr):
	c = chr - 0x20
	if (x > 128 - 1)  :
		x = 0
		y = y + 2
	OLED_Set_Pos(x, y)
	for i in range(8):
		i2c.write_byte_data(Oled_Address, 0x40, F8X16[c * 16 + i])
	OLED_Set_Pos(x, y + 1)
	for i in range(8):
		i2c.write_byte_data(Oled_Address, 0x40, F8X16[c * 16 + i + 8])

def OLED_ShowSign(x, y, c):
	if (x > 128 - 1)  :
		x = 0
		y = y + 2
	OLED_Set_Pos(x, y)
	for i in range(8):
		i2c.write_byte_data(Oled_Address, 0x40, F_SIGN[c * 16 + i])
	OLED_Set_Pos(x, y + 1)
	for i in range(8):
		i2c.write_byte_data(Oled_Address, 0x40, F_SIGN[c * 16 + i + 8])

def OLED_ShowString(x, y, chr):
	for j in range(len(chr)):
		OLED_ShowChar(x, y, ord(chr[j]))
		x += 8
		if (x > 120):
			x = 0
			y += 2

def OLED_ShowCHinese(x, y, no):
	OLED_Set_Pos(x, y)
	for t in range(16):
		i2c.write_byte_data(Oled_Address, 0x40, Hzk[2 * no][t])
	OLED_Set_Pos(x, y + 1)
	for t in range(16):
		i2c.write_byte_data(Oled_Address, 0x40, Hzk[2 * no + 1][t])

def readSensor(command):
    i2c.write_quick(eSHT2xOled_Addressess)
    i2c.write_byte(eSHT2xOled_Addressess,command)
    time.sleep(0.1)
    result =(i2c.read_byte(eSHT2xOled_Addressess)<<8)
    result += i2c.read_byte(eSHT2xOled_Addressess)
    result &= ~0x0003
    #print result
    return result


#温湿度数据提取
def getRHumidity():
    return (-6.0 + 125.0 / 65536.0 * float(readSensor(eRHumidityNoHoldCmd)))

def getTemperature():
    return (-46.85 + 175.72 / 65536.0 * float(readSensor(eTempNoHoldCmd)))

i2c.write_byte_data(Oled_Address,0x00,0xAE)
i2c.write_byte_data(Oled_Address,0x00,0x02)
i2c.write_byte_data(Oled_Address,0x00,0x10)
i2c.write_byte_data(Oled_Address,0x00,0x40)
i2c.write_byte_data(Oled_Address,0x00,0xB0)
i2c.write_byte_data(Oled_Address,0x00,0x81)
i2c.write_byte_data(Oled_Address,0x00,0xFF)
i2c.write_byte_data(Oled_Address,0x00,0xA1)
i2c.write_byte_data(Oled_Address,0x00,0xA6)
i2c.write_byte_data(Oled_Address,0x00,0xA8)
i2c.write_byte_data(Oled_Address,0x00,0x3F)
i2c.write_byte_data(Oled_Address,0x00,0xAD)
i2c.write_byte_data(Oled_Address,0x00,0x8B)
i2c.write_byte_data(Oled_Address,0x00,0x33)
i2c.write_byte_data(Oled_Address,0x00,0xC8)
i2c.write_byte_data(Oled_Address,0x00,0xD3)
i2c.write_byte_data(Oled_Address,0x00,0x00)

i2c.write_byte_data(Oled_Address,0x00,0xD5)
i2c.write_byte_data(Oled_Address,0x00,0x80)

i2c.write_byte_data(Oled_Address,0x00,0xD8)
i2c.write_byte_data(Oled_Address,0x00,0x05)

i2c.write_byte_data(Oled_Address,0x00,0xD9)
i2c.write_byte_data(Oled_Address,0x00,0x1F)

i2c.write_byte_data(Oled_Address,0x00,0xDB)
i2c.write_byte_data(Oled_Address,0x00,0x40)

i2c.write_byte_data(Oled_Address,0x00,0xAF)


Clear_Oled()


OLED_ShowCHinese(5,1,1)
OLED_ShowCHinese(22,1,2)
OLED_ShowString(40,1,":")
OLED_ShowCHinese(110,1,0)
OLED_ShowCHinese(5,4,3)
OLED_ShowCHinese(22,4,4)
OLED_ShowString(40,4,":")
OLED_ShowCHinese(110,4,5)

print "OLED Init"

i2c.write_byte(0x40, 0xFE)

print "SHT20 Init"

time.sleep(0.800)


#改：添加onenet 的api

APIKEY = 'ajwue0moVdK6pkjl9PsyjJfbXZc='  # 改成你的APIKEY


def get_temp():
    # 打开文件
    file = open("/sys/class/thermal/thermal_zone0/temp")
    # 读取结果，并转换为浮点数
    temp = float(file.read()) / 1000
    # 关闭文件
    file.close()
    # 向控制台打印结果
    print("CPU tempurature: %.3f" % temp)
    # 返回温度值
    return temp


def http_put():
    # 获取  CPU温度、温湿度数据  并上传
    #CPU_temperature = get_temp()
    #m_temp = getTemperature()
    #m_hum = getRHumidity()
    #保留两位小数
    CPU_temperature = round(get_temp(),2)
    m_temp = round(getTemperature(),2)
    m_hum =round(getRHumidity(),2)


    CurTime = datetime.datetime.now()

    # 这url只需把数字部分换成你在onenet中创建的设备号就行
    url = 'http://api.heclouds.com/devices/602743016/datapoints'

    #  onenet平台上显示的值
    values = {
        'datastreams': [
            {"id": "CPU_temp", "datapoints": [{"time": CurTime.isoformat(), "value": CPU_temperature}]},
            {"id": "m_temp", "datapoints": [{"time": CurTime.isoformat(), "value": m_temp}]},
            {"id": "m_hum", "datapoints": [{"time": CurTime.isoformat(), "value": m_hum}]}
        ]}

    print ("Cur_time:%s" % CurTime.isoformat())
    print ("tempure:%.3f" % CPU_temperature)   #CPU的温度

    jdata = json.dumps(values)  # 对数据进行JSON格式化编码
    # 打印json内容
    print jdata
    request = urllib2.Request(url, jdata)
    request.add_header('api-key', APIKEY)
    request.get_method = lambda: 'POST'  # 设置HTTP的访问方式
    request = urllib2.urlopen(request)
    return request.read()


'''
while True:
    time.sleep(5)
    resp = http_put()
    print ("OneNET_result: %s" % resp)
    # time.sleep(5)
'''



while (1):
    time.sleep(3)
    H = getRHumidity()
    T = getTemperature()

    OLED_ShowString(60, 1, str(round(T, 2)))
    OLED_ShowString(60, 4, str(round(H, 2)))
    resp = http_put()

    print "Temperature=%0.2f" % (T)
    print "Humidity=%0.2f" % (H)

    print ("OneNET_result: %s" % resp)



    #time.sleep(3)







